const db = require('./db/db');

async function fixZipField() {
  try {
    console.log('开始修改zip字段...');
    
    // 直接执行ALTER TABLE语句
    const alterSQL = "ALTER TABLE business_cards MODIFY COLUMN zip VARCHAR(100)";
    console.log(`执行SQL: ${alterSQL}`);
    
    await db.query(alterSQL);
    console.log('修改成功');
    
    // 验证修改是否生效
    const tableStructure = await db.query('DESCRIBE business_cards');
    const zipField = tableStructure.find(field => field.Field === 'zip');
    
    if (zipField) {
      console.log('\n修改后的zip字段定义:');
      console.log(`类型: ${zipField.Type}`);
      console.log(`是否允许NULL: ${zipField.Null}`);
      console.log(`默认值: ${zipField.Default}`);
    }
    
    process.exit(0);
  } catch (error) {
    console.error('修改zip字段时发生错误:', error);
    process.exit(1);
  }
}

// 执行修复
fixZipField(); 